package com.ruoyi.back.controller

import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.back.domain.AppInfo
import com.ruoyi.back.domain.AppWatermarkSetting
import com.ruoyi.back.mapper.AppWatermarkSettingMapper
import com.ruoyi.back.service.AppInfoService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/system/appInfo")
@Api(tags = ["关于我们-用户协议&隐私政策"])
class AppInfoController {

    @Autowired
    private lateinit var appInfoService: AppInfoService

    @Autowired
    private lateinit var appWatermarkSettingMapper: AppWatermarkSettingMapper


    @ApiOperation("获取用户协议&隐私政策的相关信息")
    @ApiImplicitParams(
        ApiImplicitParam(name = "type", value = "查询类型:1. 用户协议 2. 隐私政策", type = "path", required = true)
    )
    @GetMapping("get/{type}")
    fun getAppInfo(@PathVariable type: Int): Data<AppInfo> = appInfoService.getAppInfo(type)


    @GetMapping("getAppWatermark")
    @ApiOperation("获取app水印信息")
    fun getAppWatermark(): Data<AppWatermarkSetting> =
        Ok("获取成功", appWatermarkSettingMapper.selectOne(KtQueryWrapper(AppWatermarkSetting::class.java)))


    @PostMapping("settingAppWatermark")
    @ApiOperation("保存app水印信息")
    fun settingAppWatermark(@RequestBody appWatermarkSetting: AppWatermarkSetting): Data<Boolean> =
        appWatermarkSetting.id?.run {
            Ok("修改成功", appWatermarkSettingMapper.updateById(appWatermarkSetting) > 0)
        } ?: run {
            Ok("保存成功", appWatermarkSettingMapper.insert(appWatermarkSetting) > 0)
        }

    @ApiOperation("保存用户协议&隐私政策的相关信息")
    @PostMapping("save")
    fun saveAppInfo(@RequestBody appInfo: AppInfo): Data<Boolean> = appInfoService.saveAppInfo(appInfo)
}